#!/usr/bin/perl
#
# Coloured Petri Net (CPN): Example
# Release: Development
#
# Copyright (c) 2011 Brent R. Scott. All rights reserved. This program is 
# free software. You can redistribute it and/or modify it under the same
# terms as Perl itself.

use strict;
use Data::Dumper;
use CPN;

# Define		PLACES			TOKENS
my $Places = { 'Home'      => [ 'Vehicle=Motorcycle', 'Me=True' ],
               'Office'    => [ ],
               'Week'      => [ 'Weekday=2', 'Weekend=0' ],
               'Mountains' => [ ],
             };

# Define			TRANSITIONS		CODE
my $Transitions = { "CommuteIn"  => undef,
                    "CommuteOut" => undef,
                    "Journey"    => undef,
                    "Return"     => undef,
                    "SightSee"   => undef,
                  };

# Define	DIRECTION		TRANSITION		PLACE(S)			CONDITION/EXPR
my $Arcs = { "input"  => { "CommuteIn"   => { 'Home'         => 'Vehicle,Me', },
	                       "CommuteOut"  => { 'Office'       => 'Vehicle,Me', },
	                       "Journey"     => { 'Home'         => 'Vehicle,Me',
	                       	                  'Week'         => 'Weekday=5', },
	                       "Return"      => { 'Week'         => 'Weekend=2',
	                                          'Mountains'    => 'Vehicle,Me', },
	                       "SightSee"    => { 'Mountains'    => 'Vehicle,Me', },
                         },
             "output" => { "CommuteIn"   => { 'Office'       => 'Vehicle,Me', },
	                       "CommuteOut"  => { 'Home'         => 'Vehicle,Me',
	                       	                  'Week'         => 'Weekday+1', },
	                       "Journey"     => { 'Mountains'    => 'Vehicle,Me', },
	                       "Return"      => { 'Home'         => 'Vehicle,Me', },
	                       "SightSee"    => { 'Mountains'    => 'Vehicle,Me',
	                       	                  'Week'         => 'Weekend+1', },
                         },
           };

# Define a new Petri Net
my $PN=CPN->new;

# Build the Net - MUST FOLLOW FORMAT ABOVE
$PN->buildNet($Places, $Transitions, $Arcs);

my $pl=$PN->getStatePlaces();
print Dumper($pl);

exit 0;